package day13_net.com.itheima.d2_udp1;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class Server {
    public static void main(String[] args) throws IOException {
        System.out.println("服务器启动成功。。。");
        DatagramSocket socket = new DatagramSocket(10086);
        byte[] buffer = new byte[1024 * 64];
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);

        socket.receive(packet);

        int len = packet.getLength();
        String msg = new String(buffer, 0, len);
        System.out.println(msg);

        InetAddress ip = packet.getAddress();
        System.out.println("ip.getHostAddress() = " + ip.getHostAddress());
        System.out.println("packet.getPort() = " + packet.getPort());

        socket.close();
    }
}
